This is version #0, testing github pages functionality with r studio

library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.5.3
## Warning: As of rlang 0.4.0, dplyr must be at least version 0.8.0.
## x dplyr 0.7.8 is too old for rlang 0.4.2.
## i Please update dplyr to the latest version.
## i Updating packages on Windows requires precautions:
##   <https://github.com/jennybc/what-they-forgot/issues/62>
library(plotly)
## Warning: package 'plotly' was built under R version 3.5.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
require(tidyverse)
## Loading required package: tidyverse
## Warning: package 'tidyverse' was built under R version 3.5.2
## -- Attaching packages --------------------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## √ tibble  1.4.2     √ purrr   0.2.5
## √ tidyr   0.8.2     √ dplyr   0.7.8
## √ readr   1.1.1     √ stringr 1.3.1
## √ tibble  1.4.2     √ forcats 0.3.0
## Warning: package 'tidyr' was built under R version 3.5.2
## Warning: package 'purrr' was built under R version 3.5.2
## Warning: package 'dplyr' was built under R version 3.5.2
## -- Conflicts ------------------------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks plotly::filter(), stats::filter()
## x dplyr::lag()    masks stats::lag()
require(dplyr)
library(foreign)
library(haven)
library(plyr)
## Warning: package 'plyr' was built under R version 3.5.2
## -------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## -------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following object is masked from 'package:purrr':
## 
##     compact
## The following objects are masked from 'package:plotly':
## 
##     arrange, mutate, rename, summarise
gss_means = read_csv('birthcohort_means.csv')
## Parsed with column specification:
## cols(
##   survey_yr = col_integer(),
##   birth_cohort = col_double(),
##   counts = col_integer(),
##   age = col_double(),
##   polviews_wmean = col_double(),
##   happy_wmean = col_double(),
##   conrinc_wmean = col_double(),
##   dwelown_wmean = col_double(),
##   been_married_wmean = col_double(),
##   conrinc_median = col_double(),
##   is2018 = col_integer(),
##   been_married_wmean_binned = col_double()
## )
gss_means = gss_means[!gss_means$survey_yr == 1983,] #realized i should drop this too - sparse
head(gss_means)
## # A tibble: 6 x 12
##   survey_yr birth_cohort counts   age polviews_wmean happy_wmean
##       <int>        <dbl>  <int> <dbl>          <dbl>       <dbl>
## 1      1974         1900     69    74           3.93        1.61
## 2      1974         1905     97    69           4.26        1.62
## 3      1974         1910     80    64           4.08        1.54
## 4      1974         1915    107    59           4.36        1.73
## 5      1974         1920    123    54           4.21        1.66
## 6      1974         1925    105    49           4.15        1.72
## # ... with 6 more variables: conrinc_wmean <dbl>, dwelown_wmean <dbl>,
## #   been_married_wmean <dbl>, conrinc_median <dbl>, is2018 <int>,
## #   been_married_wmean_binned <dbl>
polviews_survey_yr <- ggplot(data=gss_means[gss_means$survey_yr > 1984,], aes(x=age, y=dwelown_wmean, colour=as.factor(birth_cohort))) +
  geom_line()

#ggsave('polviews_survey_yr_test1.png', plot = polviews_survey_yr, width = 20, height = 6)

ggplotly(polviews_survey_yr)
## Warning: The `printer` argument is deprecated as of rlang 0.3.0.
## This warning is displayed once per session.
## This version of Shiny is designed to work with 'htmlwidgets' >= 1.5.
##     Please upgrade via install.packages('htmlwidgets').
polviews_age <- ggplot(data=gss_means, aes(x=as.factor(survey_yr), y=birth_cohort, fill=polviews_wmean, text = paste("Sample Size:", counts, "\n Age:", age))) +
  geom_tile() + scale_fill_gradient(low="orange", high="blue") + theme(axis.text.x = element_text(angle=45))

#ggsave('polviews_age_test1.png', plot = polviews_age, width = 10, height = 6)

ggplotly(polviews_age, tooltip=c("x", "y", "fill", "text"))
## Warning: 'heatmap' objects don't have these attributes: 'showlegend'
## Valid attributes include:
## 'type', 'visible', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'z', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'transpose', 'xtype', 'ytype', 'zsmooth', 'connectgaps', 'xgap', 'ygap', 'zhoverformat', 'hovertemplate', 'zauto', 'zmin', 'zmax', 'zmid', 'colorscale', 'autocolorscale', 'reversescale', 'showscale', 'colorbar', 'coloraxis', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'zsrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
polviews_married <- ggplot(data=gss_means, aes(x=as.factor(survey_yr), y=birth_cohort, fill=as.factor(been_married_wmean_binned), text = paste("Sample Size:", counts, "\n Age:", age, "\n Marriage%:", been_married_wmean))) + scale_fill_brewer(palette="Spectral") +
  geom_tile() + theme(axis.text.x = element_text(angle=45))

#ggsave('polviews_age_test1.png', plot = polviews_age, width = 10, height = 6)

ggplotly(polviews_married, tooltip=c("x", "y", "text"))
polviews_age <- ggplot(data=gss_means, aes(x=age, y=as.factor(survey_yr), fill=conrinc_median, text = paste("Sample Size:", counts, "\n Age:", age))) +
  geom_tile() + scale_fill_gradient(low="orange", high="blue") + theme(axis.text.x = element_text(angle=45))

#ggsave('polviews_age_test1.png', plot = polviews_age, width = 10, height = 6)

ggplotly(polviews_age, tooltip=c("x", "y", "fill", "text"))
## Warning: 'heatmap' objects don't have these attributes: 'showlegend'
## Valid attributes include:
## 'type', 'visible', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'z', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'text', 'hovertext', 'transpose', 'xtype', 'ytype', 'zsmooth', 'connectgaps', 'xgap', 'ygap', 'zhoverformat', 'hovertemplate', 'zauto', 'zmin', 'zmax', 'zmid', 'colorscale', 'autocolorscale', 'reversescale', 'showscale', 'colorbar', 'coloraxis', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'zsrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
ggplot(data=gss_means, aes(x=age, y=conrinc_median, colour=as.factor(is2018))) +
  geom_point()

test_gen <- subset(gss_means, birth_cohort==1950)
ggplot(data=test_gen, aes(x=survey_yr, y=polviews_wmean)) +
  geom_line()